package com.niit.hbase.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;

import java.io.IOException;

public class WordCountDriver {


    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);
        job.setJarByClass(WordCountDriver.class);

        //创建查询实例
        Scan scan = new Scan();
        //指定要扫描的列
        scan.addColumn(Bytes.toBytes("C1"),Bytes.toBytes("receiver_phone_type"));
        //设置job读取的表
        TableMapReduceUtil.initTableMapperJob("MOMO_CHAT:MSG",scan,WordCountMapper.class, Text.class, IntWritable.class,job);

        TableMapReduceUtil.initTableReducerJob("result",WordCountReduce.class,job);

        boolean r = job.waitForCompletion(true);

        System.exit(r?0:1);

    }
}
